home *** CD-ROM | disk | FTP | other *** search
/ Programming Windows 95 / Programming Windows 95.iso / code / CHAP11 / ABOUT1.C next >
Encoding:
C/C++ Source or Header  |  1996-01-01  |  3.0 KB  |  98 lines

  1. /*------------------------------------------
  2.    ABOUT1.C -- About Box Demo Program No. 1
  3.            (c) Charles Petzold, 1996
  4.   ------------------------------------------*/
  5.  
  6. #include <windows.h>
  7. #include "about1.h"
  8.  
  9. LRESULT CALLBACK WndProc      (HWND, UINT, WPARAM, LPARAM) ;
  10. BOOL    CALLBACK AboutDlgProc (HWND, UINT, WPARAM, LPARAM) ;
  11.  
  12. int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
  13.                     PSTR szCmdLine, int iCmdShow)
  14.      {
  15.      static char  szAppName[] = "About1" ;
  16.      MSG          msg ;
  17.      HWND         hwnd ;
  18.      WNDCLASSEX   wndclass ;
  19.  
  20.      wndclass.cbSize        = sizeof (wndclass) ;
  21.      wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
  22.      wndclass.lpfnWndProc   = WndProc ;
  23.      wndclass.cbClsExtra    = 0 ;
  24.      wndclass.cbWndExtra    = 0 ;
  25.      wndclass.hInstance     = hInstance ;
  26.      wndclass.hIcon         = LoadIcon (hInstance, szAppName) ;
  27.      wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
  28.      wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
  29.      wndclass.lpszMenuName  = szAppName ;
  30.      wndclass.lpszClassName = szAppName ;
  31.      wndclass.hIconSm       = LoadIcon (hInstance, szAppName) ;
  32.  
  33.      RegisterClassEx (&wndclass) ;
  34.  
  35.      hwnd = CreateWindow (szAppName, "About Box Demo Program",
  36.                           WS_OVERLAPPEDWINDOW,
  37.                           CW_USEDEFAULT, CW_USEDEFAULT,
  38.                           CW_USEDEFAULT, CW_USEDEFAULT,
  39.                           NULL, NULL, hInstance, NULL) ;
  40.  
  41.      ShowWindow (hwnd, iCmdShow) ;
  42.      UpdateWindow (hwnd) ; 
  43.  
  44.      while (GetMessage (&msg, NULL, 0, 0))
  45.           {
  46.           TranslateMessage (&msg) ;
  47.           DispatchMessage (&msg) ;
  48.           }
  49.      return msg.wParam ;
  50.      }
  51.  
  52. LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
  53.      {
  54.      static WNDPROC   lpfnAboutDlgProc ;
  55.      static HINSTANCE hInstance ;
  56.  
  57.      switch (iMsg)
  58.           {
  59.           case WM_CREATE :
  60.                hInstance = ((LPCREATESTRUCT) lParam)->hInstance ;
  61.                return 0 ;
  62.  
  63.           case WM_COMMAND :
  64.                switch (LOWORD (wParam))
  65.                     {
  66.                     case IDM_ABOUT :
  67.                          DialogBox (hInstance, "AboutBox", hwnd, AboutDlgProc) ;
  68.                          return 0 ;
  69.                     }
  70.                break ;
  71.      
  72.           case WM_DESTROY :
  73.                PostQuitMessage (0) ;
  74.                return 0 ;
  75.           }
  76.      return DefWindowProc (hwnd, iMsg, wParam, lParam) ;
  77.      }
  78.  
  79. BOOL CALLBACK AboutDlgProc (HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam)
  80.      {
  81.      switch (iMsg)
  82.           {
  83.           case WM_INITDIALOG :
  84.                return TRUE ;
  85.  
  86.           case WM_COMMAND :
  87.                switch (LOWORD (wParam))
  88.                     {
  89.                     case IDOK :
  90.                     case IDCANCEL :
  91.                          EndDialog (hDlg, 0) ;
  92.                          return TRUE ;
  93.                     }
  94.                break ;
  95.           }
  96.      return FALSE ;
  97.      }
  98.